
/**
 * 时间戳转换
 * @param { date } 时间戳
 */
export const forDate = (date: number) => {
  if (date) {
    const time = new Date(date)
    const Y = time.getFullYear()
    const M = forDateConversion(time.getMonth() + 1)
    const D = forDateConversion(time.getDate())
    const h = forDateConversion(time.getHours())
    const m = forDateConversion(time.getMinutes())
    return `${Y}-${M}-${D} ${h}:${m}`
  }
  return ''
}

/**
 * 格式化   年 月 日
 */
export const formateDate = (date: any) => {
  if (date) {
    const time = new Date(date)
    const Y = time.getFullYear()
    const M = forDateConversion(time.getMonth() + 1)
    const D = forDateConversion(time.getDate())
    return `${Y}-${M}-${D}`
  }
  return ''
}
export const forDateConversion = (Time: number | string) => {
  Time = (Time as number) >= 10 ? Time : '0' + Time
  return Time
}

export const forHour = (date: number) => {
  if (date) {
    const time = new Date(date)
    const Y = time.getFullYear()
    const M = forDateConversion(time.getMonth() + 1)
    const D = forDateConversion(time.getDate())
    const h = forDateConversion(time.getHours())
    const m = forDateConversion(time.getMinutes())
    const ss = forDateConversion(time.getSeconds())
    return `${h}:${m}`
  }
  return ''
}
export const forSeconds = (date: any) => {
  const timesTamp = new Date()
  const nowSeconds = timesTamp.getTime()
  return date - nowSeconds
}
export const forNowTime = (date: any) => {
  let H: any = ''; let M: any = '';
  const timesTamp = new Date()
  const nowSeconds = timesTamp.getTime()
  const diff = date - nowSeconds
  const rh = diff % (24 * 3600 * 1000)
  const h: any = Math.floor(rh / (3600 * 1000));
  H = h < 10 ? '0' + h : h
  let rm = rh % (3600 * 1000);
  let m = Math.floor(rm / (60 * 1000));
  M = m < 10 ? '0' + m : m;
  const str: any = `${H}:${M}`
  return str
}

export const textTime = (date: any) => {
  const timesTamp = new Date()
  const nowSeconds = timesTamp.getTime()
  const nowDays = timesTamp.getDate()
  const Time = new Date(date)
  const lsitD = Time.getDate()
  const tetxtName = lsitD - nowDays <= 0 ? '今日' : '明日'

  return `${tetxtName}${forHour(date)}`
}
export const nowDate = () => {
  const time = new Date()
  const Y = time.getFullYear()
  const M = forDateConversion(time.getMonth() + 1)
  const D = forDateConversion(time.getDate())
  return `${Y}${M}${D}`
}
